package com.example.controller;

import com.example.common.result.Result;
import com.example.entity.Attendance;
import com.example.entity.dto.AttendanceDto;
import com.example.entity.dto.AttendanceSearch;
import com.example.entity.vo.AttDataVO;
import com.example.entity.vo.AttVO;
import com.example.entity.vo.AttendanceVO;
import com.example.service.AttendanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.util.List;


@RestController
@RequestMapping("/att")
@Slf4j
@Api(tags = "考勤相关接口")
public class AttendanceController {

    @Autowired
    private AttendanceService attendanceService;

    /**
     * 添加今日考勤
     * @param attendanceDto
     */
    @PostMapping("/add")
    @ApiOperation("添加今日考勤")
    private Result addAttendance(@RequestBody AttendanceDto attendanceDto){
        log.info("添加今日考勤:{}",attendanceDto);
        attendanceService.addAttendance(attendanceDto);
        return Result.success();
    }

    /**
     * 查看具体考勤
     * @param id
     * @return
     */
    @GetMapping("/get")
    @ApiOperation("查看具体考勤")
    private Result<AttendanceVO> findAttendance(@RequestParam int id){
        log.info("查看具体考勤:{}",id);
        AttendanceVO attendanceVO = attendanceService.findAtt(id);
        return Result.success(attendanceVO);
    }

    /**
     *
     * 查看当日考勤
     * @param date
     * @return
     */
    @GetMapping("/getlist")
    @ApiOperation("查看当日考勤")
    private Result<List<AttendanceVO>> findAttList(@RequestParam Date date){
        log.info("查看当日考勤：{}",date);
        List<AttendanceVO> list = attendanceService.getList(date);
        return Result.success(list);
    }

    /**
     * 修改具体考勤
     * @param attendance
     * @return
     */
    @PostMapping("/updata")
    @ApiOperation("修改具体考勤")
    private Result updateAtt(@RequestBody Attendance attendance){
        log.info("修改具体考勤:{}",attendance);
        attendanceService.updateAtt(attendance);
        return Result.success();
    }

    /**
     * 删除考勤
     * @param id
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation("删除考勤")
    private Result deleteAtt(@RequestParam int id){
        log.info("删除考勤:{}",id);
        attendanceService.deleteAtt(id);
        return Result.success();
    }

    /**
     * 获取员工当月工作考勤
     * @param employeeId
     * @param date
     * @return
     */
    @GetMapping ("/findWorkingTime")
    @ApiOperation("获取员工当月工作考勤")
    private Result<List<AttDataVO>> findAttWorkingData(@RequestParam int employeeId,@RequestParam String date){
        log.info("获取员工当月工作考勤:{},{}",employeeId,date);

        List<AttDataVO> attDataVOList = attendanceService.findAttWorkingData(employeeId,date);

        return Result.success(attDataVOList);

    }

    @GetMapping("/findOverTime")
    @ApiOperation("获取员工当月加班考勤")
    private Result<List<AttDataVO>> findAttOverData(@RequestParam int employeeId,@RequestParam String date){
        log.info("获取员工当月加班考勤:{},{}",employeeId,date);

        List<AttDataVO> attDataVOList = attendanceService.findAttOverData(employeeId,date);
        return Result.success(attDataVOList);
    }

    /**
     * 获取总结当月考勤
     * @param employeeId
     * @param date
     * @return
     */
    @GetMapping("/find")
    @ApiOperation("获取总结当月考勤")
    private Result<AttVO> findAttData(@RequestParam int employeeId,@RequestParam String date){
        log.info("获取总结当月考勤:{},{}",employeeId,date);
        AttVO attVO = attendanceService.findAttData(employeeId,date);
        return Result.success(attVO);
    }

    /**
     * 综合查询
     * @param attendanceSearch
     * @return
     */
    @PostMapping("/search")
    @ApiOperation("综合查询")
    private Result<List<AttendanceVO>> search(@RequestBody AttendanceSearch attendanceSearch){
        log.info("综合查询:{}",attendanceSearch);
        List<AttendanceVO> list = attendanceService.search(attendanceSearch);
        return Result.success(list);
    }
}
